/**
 * Copyright &copy; 2012-2013 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 */
package com.oplink.webems.modules.sys.dao;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import com.oplink.webems.common.persistence.BaseDao;
import com.oplink.webems.common.persistence.BaseDaoImpl;
import com.oplink.webems.modules.sys.entity.Dict;

/**
 * 字典DAO接口
 * 
 * @author ThinkGem
 * @version 2013-01-15
 */
public interface DictDao extends DictDaoCustom, CrudRepository<Dict, Long> {

	Page<Dict> findByUserId(Long id, Pageable pageRequest);

	@Modifying
	@Query("delete from Dict dic where user.id=?1")
	void deleteByUserId(Long id);

	@Modifying
	@Query("update Dict set delFlag='" + Dict.DEL_FLAG_DELETE + "' where id = ?1")
	public int deleteById(Long id);

	@Query("from Dict where delFlag='" + Dict.DEL_FLAG_NORMAL + "' AND user.id = ?1 ORDER BY sort")
	public List<Dict> findAllListById(Long id);

	@Query("from Dict where delFlag='" + Dict.DEL_FLAG_NORMAL + "' AND user.id = ?1 GROUP BY type")
	public List<Dict> findAllListByType(Long id);
}

interface DictDaoCustom extends BaseDao<Dict> {
}

class DictDaoImpl extends BaseDaoImpl<Dict> implements DictDaoCustom {
}
